Ext.define('Lms.rms.AdminInfoDialog',{
	openWindow : function(config) {
		Ext.apply(this, config);
		this.isEditableMode = false; 
		var title = LocaleUtil.getMessage('rms.label.admin');
		if(typeof(config) != 'undefined'){
			title += LocaleUtil.getMessage('rms.label.detail');
			this.isEditableMode = true;
		}else{
			title += LocaleUtil.getMessage('reg');
		}
		this.dialog = Common.openDialog(title, 400, null, [{
			text : (this.isEditableMode)?LocaleUtil.getMessage('update'):LocaleUtil.getMessage('reg'),
			scope : this,
			hidden : (loginAuth != 'S')?true:false,
			handler : function(){
				if(!this.form.isValid()) return;
				Common.confirm(LocaleUtil.getMessage('confirm'),LocaleUtil.getMessage('rms.msg.doYouWantToSave'),function(btn){
					if(btn == 'yes'){
						this.onSubmit();
					}
				},this);
			}
		},{
			text : LocaleUtil.getMessage('close'),
			cls : 'blue_button',
			scope : this,
			handler : function() {
				this.dialog.close();
				Ext.getCmp('AdminMgmPanel').getStore().reload();
			}
		}]);
		this.dialog.resizable = true;
//		this.dialog.iconCls = 'detail_search';
		this.dialog.add(this.getForm());
		this.dialog.show();
		if(this.isEditableMode){
			this.getData();
		}
	},
	
	onSubmit : function(){
		var url;
		if(this.isEditableMode){
			//수정 logic
			url = 'admin/update.do';
		}else{
			//등록 url
			url = 'admin/create.do';
		}
		if(!this.form.isValid()) return;
		
		//form submit
//		Common.formSubmit({
//			url : url,
//			params : this.form.getValues(),
//			reloadPanelId : 'AdminMgmPanel',
//			closeDialog : this.dialog
//		},this);
		this.form.getForm().submit({
			url : url,
			scope : this,
			success : function(form, action){
				Ext.getCmp('AdminMgmPanel').getStore().reload();
				this.dialog.close();
			},
			failure : Common.failureMessageSubmit
		}); 	    
	},
	
	getData : function(){
		this.form.load({
			url : 'admin/findInfo.do',
			params : {
				id : this.id
			}
		});
	},
	
	getForm : function(){
		// Add the additional 'advanced' VTypes
	    Ext.apply(Ext.form.field.VTypes, {
	        password: function(val, field) {
	            if (field.initialPassField) {
	                var pwd = field.up('form').down('#' + field.initialPassField);
	                return (val == pwd.getValue());
	            }
	            return true;
	        },
	        passwordText: 'Passwords do not match'
	    });
	    
		this.form = Ext.widget('form',{
			frame : false,
		    border : false,
		    region : 'north',
		    bodyPadding: '5 5 0',
	        defaults: {anchor: '100%'},
	        defaultType: 'textfield',
	        fieldDefaults: {
	        	labelAlign : 'right',
                labelWidth: 120,
                msgTarget : 'side'
            },
	        items :[{
	        		fieldLabel : LocaleUtil.getMessage('rms.label.adminId'),
	        		allowBlank : false,
	        		name : 'id',
	        		readOnly : this.isEditableMode
                },{            	
                    fieldLabel: LocaleUtil.getMessage('rms.label.name'),
                    name: 'name',
                    allowBlank : false,
                    readOnly : false
                },{
                	xtype : 'combobox',
                	store : ['S','A','N'],
                	name: 'auth',
                	fieldLabel: LocaleUtil.getMessage('rms.label.permissions'),
                	forceSelection: true,
                	editable: false,
                	allowBlank : false
                },{
                    fieldLabel: LocaleUtil.getMessage('rms.label.email'),
                    name: 'email',
                    allowBlank : false,
                    readOnly : false
                },{
                	itemId : 'pw',
                	inputType: 'password',
                    fieldLabel: LocaleUtil.getMessage('rms.label.password'),
                    name: 'pw',
                    allowBlank : false/*,
                    listeners: {
                        validitychange: function(field){
                            field.next().validate();
                        },
                        blur: function(field){
                            field.next().validate();
                        }
                    }*/
				},{
					itemId : 'pwConfirm',
					inputType: 'password',
					fieldLabel: LocaleUtil.getMessage('rms.label.confirmPassword'),
					name: 'pwConfirm',
					vtype: 'password',
					initialPassField: 'pw',
					allowBlank : false
				}
            ]      
		});
//		if(this.isEditableMode){
//			this.form.remove(this.form.queryById('pwConfirm'),true);
//			this.dialog.setHeight(240);
//		}
		return this.form;
	}	
	
});